package com.di.base.config;

import io.seata.saga.engine.serializer.impl.ExceptionSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.StandardCharsets;

@Configuration
public class SeataSagaConfig {
    @Bean
    public ExceptionSerializer exceptionSerializer() {
        return new ExceptionSerializer() {
            @Override
            public byte[] serialize(Exception e) {
                return e.getMessage().getBytes(StandardCharsets.UTF_8);
            }

            @Override
            public Exception deserialize(byte[] bytes) {
                return new RuntimeException(new String(bytes, StandardCharsets.UTF_8));
            }
        };
    }
}